<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="search" :inline="true">
      <el-form-item label="附属品名称" prop="accessory_name">
        <el-input
          v-model="search.name"
          placeholder="请输入附属品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="list" stripe size="mini">
      <el-table-column label="操作人" width="100" align="left" prop="creator_name" />
      <el-table-column label="折旧名称" width="220" align="left" prop="name" />
      <el-table-column label="多少月后" width="150" align="left" prop="months" />
      <el-table-column label="创建时间" width="180" align="left" prop="create_datetime" />
      <el-table-column label="折旧后价值" width="180" align="left" prop="depreciation_min" />
      <el-table-column label="最后更新时间" align="left" prop="update_datetime" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

import { listDepreciations } from "@/api/vadmin/basic/depreciations";

export default {
  name: "UserCheckoutReport",
  data() {
    return {
      list: [],
      // 总条数
      total: 0,
      showSearch: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        accessory: null
      },
      search: {
        name: undefined
      }
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.search.name) {
        listAccessories(this.search).then(res => {
          let accessory = 0;
          if (res.data.results.length > 0) {
            accessory = res.data.results[0].id;
          }
          this.queryParams.accessory = accessory;
          this.getList();
        });
      } else {
        this.getList();
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.search.name = undefined;
      this.queryParams.accessory = null;
      this.handleQuery();
    },
    getList() {
      listDepreciations(this.queryParams).then(res => {
        this.list = res.data.results;
        this.total = res.data.count;
      });
    },
    clickAUser() {
      alert("暂未实现");
    }
  }
};
</script>

<style lang="scss" scoped></style>
